#!/bin/sh
# Copyright (c) 2010, Sean A.O. Harney <sharney3@gmail.com>

CONTRIB_DIR="contrib"
REGLDG_NAME="${CONTRIB_DIR}/regldg-1.0.0"
REGLDG_TAR="${REGLDG_NAME}.tar.gz"
REGLDG_PATCH="regldg-1.0.0-base64-nodeps.patch"
#REGLDG_PATCH="regldg-1.0.0-base64.patch" # alternative
REGLDG_PATCHED_NAME="${CONTRIB_DIR}/regldg-1.0.0-base64"
REGLDG_PATCHED_FILE="${REGLDG_PATCHED_NAME}/b64.c"

function patch_regldg {
	set -x ;
	tar xzvf ${REGLDG_TAR} -C ${CONTRIB_DIR} ;
	patch -d ${REGLDG_NAME} < ${REGLDG_PATCH} ;
	mv -f ${REGLDG_NAME} ${REGLDG_PATCHED_NAME} ;
	set +x ;
	echo "Finished untarring and patching regldg." ;
}

if [ -d ${REGLDG_PATCHED_NAME} ]; then
	if [ -e ${REGLDG_PATCHED_FILE} ]; then
		echo "Already have patched regldg." ;
	else
	rm -rf "${REGLDG_PATCHED_NAME}" ;
	    patch_regldg ;
	fi
else
	    patch_regldg ;
fi

set -x
# make symlinks internal to this package dir
rmdir src/contrib; #incase make dist made it a dir
rm -f src/contrib && ln -s ../contrib src/contrib ;
rm -rf docs/man && ln -s ../man docs/man ;
rm -f omf && ln -s src/omf omf ;
set +x
echo "##################################################################"
echo " bootstrap.sh is finished"
echo " For both SVN and tarball: ./configure && make"
echo "##################################################################"
#echo "Running autoreconf." ;
#autoreconf -i;
#autoreconf -i;
echo "bootstrap.sh completed." ;
exit 0 ;
